package logic

import (
	"context"
	"gitignore/models/cache"
	"math/rand"
	"time"

	"gitignore/gitignorerpc/gitignorerpc"
	"gitignore/gitignorerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *gitignorerpc.SendSmsRequest) (*gitignorerpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	Code := rand.Intn(9000) + 1000

	//sms, err := pkg.SendSms(in.PhoneNum, Code)
	//if err != nil {
	//	return nil, errors.New("验证码发送错误")
	//}
	//
	//if sms.Code == 2 {
	//	return nil, errors.New(sms.Msg)
	//}

	cache.Rdb.Set(l.ctx, "sendSms"+in.PhoneNum, Code, time.Minute*10)

	return &gitignorerpc.SendSmsResponse{}, nil
}
